package com.controller;

import com.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
public class PasswordController {

    @Autowired
    private UserService userService;

    @ResponseBody
    @RequestMapping(value = "/updatePassword.do",method = RequestMethod.POST)
    public String updatePassword(Long uid,String oldPassword,String newPassword){
        String password = userService.findPasswordById(uid.intValue());
        if (!password.equals(oldPassword)){
            return "errorPassword";
        }else {
            boolean isok = userService.doUpdatePassword(uid.intValue(), newPassword);
            if (isok){
                return "true";
            }else {
                return "false";
            }
        }
    }
}
